<?php
/**
 * @copyright TinyWEB CMS
 * @link http://tinywebcms.ru
 * @link http://cms.vingrad.ru
 *
 */
class ApplicationExecutableController extends ApplicationController implements IExecutable 
{
    /**
     * Controllers collection
     *
     * @var array
     */
    protected $controllers = array();
    
    final public function __construct()
    {
        $this->onConstruct();
    }
    
    public function onConstruct() {}
    
    public function push(ApplicationController $controller)
    {
        $this->controllers[$controller->getInstanceName()] = $controller;
    }
    
    public function __callstack()
    {
        $output = array();
        foreach ($this->controllers as $controller) {
            if($controller instanceof INeedsParentObject) {
                $controller->setParent($this);
            }
            
            if($controller instanceof IExecutable) {
                $controller->exec();
            }
        }
    }
    
    public function exec() {}
}

?>